﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using COMOSOFT.Class;
using DevExpress.XtraRichEdit.API.Word;

namespace COMOSOFT.WareHouse_Management.Forms
{
    public partial class FrmStockGaneralView : Form
    {
        ClassShare cls = new ClassShare("FrmStockGaneralView");
        string item = null;
        List<object> ListItem = new List<object>();
        int MAID, MADID,MAEXCID;
        double ExcQty;
        public FrmStockGaneralView()
        {
            InitializeComponent();
        }
        public void LoadData()
        {
            sp_WHStockGaneralViewTableAdapter.Fill(this.dataSet_WareHouse.sp_WHStockGaneralView);
        }

        #region[Add Stock]
        private void dataNavigator_Stock_ButtonClick(object sender, DevExpress.XtraEditors.NavigatorButtonClickEventArgs e)
        {
            try
            {
                if (e.Button.Tag.ToString() == "Add")
                {
                    GridView view = gridView_AddStock as GridView;
                    int[] arrMA = view.GetSelectedRows();
                    foreach (int index in arrMA)
                    {
                        MAID = Convert.ToInt32(view.GetDataRow(index)["MAID"]);
                        MADID = Convert.ToInt32(view.GetDataRow(index)["MADID"]);
                        ExcQty = Convert.ToInt32(view.GetDataRow(index)["RemainQty"]);
                        cls.UpdateData("sp_WHStockInsert", new string[] { "@MAID", "@MADID", "@IssueDate", "@Creater", "@ExcQty" }, new object[] { MAID, MADID, DateTime.Now, ClassShare.Usid, ExcQty });
                        dockPanel_AddStock.Close();
                        LoadData();
                    }
                }
                else
                {
                    dockPanel_AddStock.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void checkedComboBoxEdit_TrimList_Closed(object sender, DevExpress.XtraEditors.Controls.ClosedEventArgs e)
        {
            if (e.CloseMode.ToString() == "Normal")
            {
                item = null;
                ListItem = checkedComboBoxEdit_TrimList.Properties.Items.GetCheckedValues();
                if (ListItem.Count > 0)
                {
                    foreach (object it in ListItem)
                    {
                        item += it.ToString() + ",";
                    }
                    sp_WHStockViewTableAdapter.Fill(dataSet_WareHouse.sp_WHStockView, item);
                    gridView_AddStock.ClearSelection();
                }
                else
                    MessageBox.Show("BookNo is empty!");
            }
        }
        #endregion

        public void ShowPanel()
        {
            dockPanel_AddStock.Show();
        }
        private void FrmStockGaneralView_Load(object sender, EventArgs e)
        {            
            this.sp_BAMenuTableAdapter.Fill(this.dataSetBalancing.sp_BAMenu);
        }

        public void ClareStock()
        {
            try
            {
                if (MessageBox.Show("Are you sure delete?", "Confirm Delete!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    GridView view = gridView_StockView as GridView;
                    int[] arrStock = view.GetSelectedRows();
                    foreach (int index in arrStock)
                    {
                        MAEXCID = Convert.ToInt32(view.GetDataRow(index)["MAEXCID"]);
                        cls.UpdateData("sp_WHStockClare", new string[] { "@MAEXCID" }, new object[] { MAEXCID });
                    }
                    LoadData();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
